using System.Runtime.Serialization;
using MiniStock.Entities.Common;

namespace MiniStock.Entities.Stock.Events.Product
{
    [DataContract]
    public class CreateProductEvent : ProductEventBase
    {
        [DataMember]
        public string Name { get; set; }

        [DataMember]
        public string ProductNumber { get; set; }

        public override void ValidateFor(EntityBase entity, IEntityProvider provider)
        {
            base.ValidateFor(entity, provider);
            var item = (Stock.Product) entity;

            Stock.Product.Validator.ProductNameMandatory(item, provider, Name);
            Stock.Product.Validator.ProductNameUnique(item, provider, Name);

            Stock.Product.Validator.ProductNumberMandatory(item, provider, ProductNumber);
            Stock.Product.Validator.ProductNumberUnique(item, provider, ProductNumber);
        }

        public override void ApplyTo(EntityBase entity)
        {
            var typedEntity = (Stock.Product) entity;
            typedEntity.Name = this.Name;
            typedEntity.Id = this.Id;
            typedEntity.ProductNumber = this.ProductNumber;
        }
    }
}